package com.wlyuan.open.scanner.repository.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wlyuan.open.scanner.dao.entity.ExtensionTopWarehouseDO;
import com.wlyuan.open.scanner.dao.mapper.ExtensionTopWarehouseMapper;
import com.wlyuan.open.scanner.repository.ExtensionTopWarehouseRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import lombok.var;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

/**
 * @author lijing
 * @description
 */
@Service
@Slf4j
@RequiredArgsConstructor
public class ExtensionTopWarehouseRepositoryImpl implements ExtensionTopWarehouseRepository {
    private final ExtensionTopWarehouseMapper extensionTopWarehouseMapper;

    @Override
    public ExtensionTopWarehouseDO getByCode(String code) {
        if (StringUtils.isBlank(code)) {
            return null;
        }
        LambdaQueryWrapper<ExtensionTopWarehouseDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ExtensionTopWarehouseDO::getTopWarehousecode, code);
        var list = extensionTopWarehouseMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.stream().findFirst().get();
    }
}
